package com.tv.enoguia;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.TextView;

import com.tv.enoguia.adapter.ListCategoriesAdapter;
import com.tv.enoguia.database.MySQLiteHelper;

public class ListCategoriesActivity extends Activity {
	
	TextView title;
	ListView listCategories;
	ListCategoriesAdapter adapter;
//	ArrayList<Categories> categories = new ArrayList<Categories>();
	ArrayList<String> categories = new ArrayList<String>();
	MySQLiteHelper db;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_list_categories);
		
		db = new MySQLiteHelper(this);
		
		/*if (MainActivity.getCurrentTab() == 0){
			finish();
		}*/
		
		title = (TextView) findViewById(R.id.title);
		listCategories = (ListView) findViewById(R.id.list_categories);
		
		dataDemo();
		adapter = new ListCategoriesAdapter(ListCategoriesActivity.this, categories);
		listCategories.setAdapter(adapter);
		init();
		
		
		listCategories.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View v, int positon,
					long arg3) {
				Intent t = new Intent(ListCategoriesActivity.this, ListBussinessActivity.class);
				t.putExtra("category", categories.get(positon));
				startActivity(t);
				
			}
			
		});
	}
	

	void dataDemo(){
		/*categories.add(new Categories("DO Catalunya"));
		categories.add(new Categories("DO Conca de Barbera"));
		categories.add(new Categories("DO Montsant"));
		categories.add(new Categories("DO Penedes"));
		categories.add(new Categories("DOQ Priorat"));
		categories.add(new Categories("DO Tarragona"));
		categories.add(new Categories("DO Terra Alta"));*/
		categories = db.getCategories();
	}
	
	
	void init(){
		title.setText(getString(R.string.denomimos));
	}
}
